﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Threading;
using System.Configuration;

namespace _4591BRD
{
    public partial class Service1 : ServiceBase
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            Service1 app = new Service1();
            if (Common.IsConsole)
            {
                Log.WriteLine(1, "Console ON!!!");
                app.OnStart(null);
                Log.WriteLine(1, "Press any key to exit.");
                Console.ReadKey();
            }
            else
            {
                Log.WriteLine(1, "Service ON!!!");
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { app };
                ServiceBase.Run(ServicesToRun);
            }
        }

        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Log.WriteLine(1, "Service OnStart");

            //set Max Thread Num      
            int maxThreadNum = int.Parse(ConfigurationSettings.AppSettings["MaxThreadNum"].ToString());
            ThreadPool.SetMaxThreads(maxThreadNum, maxThreadNum * 2);

            //GeneralRank.Instance.Run();
            //MonthlyRank.Instance.Run();
            //DailyRank.Instance.Run();
            BRDWork.Instance.Run();
        }

        protected override void OnStop()
        {
            Log.WriteLine(1, "Service OnStop");
        }
    }
}
